const async           = require('async');
const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class MarketingProbeProxyHandler extends BaseHandler {

    get pattern() {
        return "/proxy/:url/:wall_id";
    }

    doGET(request, response) {
        let wallId = request.params.wall_id;
        let url = request.params.url;
        url = url.replace(/-/g, '/');
        url = atob(url);
        
        if (!request.session.walls || request.session.walls && !request.session.walls[wallId]) {
            return response.end(url);
        }

        this.Controller.fetchContent(url, (content) => {
            response.end(content);
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = MarketingProbeProxyHandler;